package com.umeox.ota.gloable;

import android.app.Application;
import android.content.Context;

import com.umeox.ota.data.repository.RepositoryComponentImpl;
import com.umeox.ota.data.repository.RepositoryConfigModule;
import com.umeox.ota.data.repository.base.IRepository;
import com.umeox.ota.data.repository.base.RepositoryComponent;
import com.umeox.ota.lifecycle.AppLifecycles;



/**
 * @author fighter_lee
 * Application 生命周期代理接口实现类
 */
public class AppDelegate implements AppLifecycles, IRepository {
    private Application mApplication;
    private RepositoryComponent repositoryComponent;

    public AppDelegate(Application app) {
        this.mApplication = app;
    }

    @Override
    public void attachBaseContext(Context context) {

        if (repositoryComponent == null) {
            RepositoryConfigModule configModule = RepositoryConfigModule.builder().build();
            repositoryComponent = RepositoryComponentImpl.builder()
                    .setApplication(mApplication)
                    .setRepositoryConfigModule(configModule)
                    .build();
        }
    }

    @Override
    public void onCreate(Application application) {
        this.mApplication = application;

    }

    @Override
    public void onTerminate(Application application) {
        this.mApplication = null;
    }

    @Override
    public RepositoryComponent getRepositoryComponent() {
        return repositoryComponent;
    }
}